package com.exam.sacrifice.ui.mine;

import android.view.View;

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.GridLayoutManager;

import com.exam.commonbiz.base.BaseActivity;
import com.exam.commonbiz.base.BaseViewModel;
import com.exam.commonbiz.util.OnFastClickListener;
import com.exam.commonbiz.util.ToastUtil;
import com.exam.sacrifice.R;
import com.exam.sacrifice.databinding.ActivityRechargeCenterBinding;
import com.exam.sacrifice.ui.adapter.RechargeCenterAdapter;
import com.exam.sacrifice.ui.bean.RechargeInfo;

import java.util.ArrayList;
import java.util.List;

public class RechargeCenterActivity extends BaseActivity<BaseViewModel, ActivityRechargeCenterBinding> {

    @Override
    public void initData() {

        binding.ivBack.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                finish();
            }
        });

        binding.ivRecord.setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                ToastUtil.getInstance().showToast("功能开发中");
            }
        });

        List<RechargeInfo> rechargeInfoList = new ArrayList<>();
        rechargeInfoList.add(new RechargeInfo("¥30", "送3元", 1));
        rechargeInfoList.add(new RechargeInfo("¥50", "送5元", 0));
        rechargeInfoList.add(new RechargeInfo("¥100", "送12元", 0));
        rechargeInfoList.add(new RechargeInfo("¥200", "送26元", 0));
        rechargeInfoList.add(new RechargeInfo("¥500", "送68元", 0));
        rechargeInfoList.add(new RechargeInfo("自定义", "金额", 0));

        RechargeCenterAdapter rechargeCenterAdapter = new RechargeCenterAdapter();
        GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 3);
        binding.recyclerView.setLayoutManager(gridLayoutManager);
        binding.recyclerView.setAdapter(rechargeCenterAdapter);
        rechargeCenterAdapter.setNewData(rechargeInfoList);
        rechargeCenterAdapter.setOnItemClickListener(new RechargeCenterAdapter.OnItemClickListener() {

            @Override
            public void onItemClick(RechargeInfo item) {
                rechargeCenterAdapter.clear();
                item.checked = 1;
                rechargeCenterAdapter.notifyDataSetChanged();

                binding.tvFee.setText(item.fee);
            }
        });

        binding.llAli.setOnClickListener(v->{
            binding.ivAli.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.recharge_checked));
            binding.ivWx.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.recharge_unchecked));
            binding.ivBank.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.recharge_unchecked));
        });

        binding.llWx.setOnClickListener(v->{
            binding.ivWx.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.recharge_checked));
            binding.ivAli.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.recharge_unchecked));
            binding.ivBank.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.recharge_unchecked));
        });

        binding.llBank.setOnClickListener(v->{
            binding.ivBank.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.recharge_checked));
            binding.ivAli.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.recharge_unchecked));
            binding.ivWx.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.recharge_unchecked));
        });
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_recharge_center;
    }
}